home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Sample Code / Snippets / Toolbox / Scrap Parsing / Scrap Parsing next >
Encoding:
Text File  |  1993-03-24  |  1.8 KB  |  50 lines  |  [TEXT/MPS ]

  1. What's in the Scrap?????
  2.  
  3. This question comes in to DTS every so often, so here's the answer.
  4.  
  5. First a NOTE:  This only applies to the in-memory scrap!  This is NOT
  6. the ScrapBook format, that is covered in a seperate tech note entitled
  7. Scrapbook File Format.
  8.  
  9. The scrap is simply a handle containing chunks of data.  The basic format
  10. is
  11. OSType        OSType of this scrap data
  12. long         Size of this scrap data
  13. {variable}     The actual data
  14.  
  15. So, you can walk through the scrap by getting the scrap handle (with InfoScrap)
  16. and advancing through the records.  That's what the function
  17. ParseScrap()
  18. in this small sample does, please steal as needed.
  19.  
  20. To see multiple formats in the Scrap, launch Simple and switch to the Finder.
  21. Do a GetInfo on a Finder icon, select the icon in the Info Window, and do a
  22. 'Copy'.  Now switch back to Simple and you'll see that the Finder has 
  23. put 7 different types in the Scrap.
  24.  
  25. Some interesting notes:
  26.  
  27. • You can add multiple formats to the current scrap (like the Finder does for icons)
  28. just by calling PutScrap repeatedly.  PutScrap appends whatever data you pass in
  29. to the existing scrap handle with a simple PtrToHand(...) call.
  30. This means, by the way, that there is NO checking for the existence of that
  31. type in the scrap already!
  32. If you do a 
  33. PutScrap(textLen,'TEXT', textPtr);
  34. PutScrap(textLen,'TEXT', textPtr);
  35.  
  36. You will now have two TEXT's in the scrap handle.
  37.  
  38. Of course, only the first one is accessable with GetScrap, because the Scrap Manager will 
  39. stop when it finds the first.
  40.  
  41. This happens because the Scrap Manager _assumes_ that you have called ZeroScrap
  42. before you call PutScrap.
  43.  
  44. • Odd data.  If the data you add to the scrap has an odd length (like, 13 text 
  45. characters) then the Scrap Manager adds 1 to make the handle even.  You'll notice
  46. I'm checking for and correcting for that in ParseScrap.
  47.  
  48.  
  49. C.K. Haun
  50. DTS